package <%=basePackage%>.dao;

import java.util.Date;
import java.util.List;

import javax.persistence.Query;

import org.springframework.stereotype.Repository;
import cn.javacc.core.database.BaseDao;
import cn.javacc.util.Status;

import <%=className%>;

@Repository
public class <%=simpleClassName%>Dao extends BaseDao<<%=simpleClassName%>> {
     public <%=simpleClassName%>Dao() {
		super(<%=simpleClassName%>.class);
	}
	
    @SuppressWarnings("unchecked")
    public List<<%=simpleClassName%>> findAll(int offset, int fetchSize) {
        Query query = entityManager.createQuery("from <%=simpleClassName%> where status > 0");
        query.setFirstResult(offset);
        query.setMaxResults(fetchSize);
        return query.getResultList();
    }

    public int getTotalSize() {
        Query query = entityManager.createQuery("select count(<%=entity%>) from <%=simpleClassName%> <%=entity%> where <%=entity%>.status > 0");
        return ((Long) query.getSingleResult()).intValue();
    }

    public void delete(Long id) {
    	entityManager.createQuery("update <%=simpleClassName%> set status=?1,lastUpdateTime=?2 where id=?3").setParameter(1, Status.DELETE).setParameter(2, new Date()).setParameter(3, id).executeUpdate();
    }
}
